<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Array</title>
    <script>
        let values = [1, 2, 3, 4, 5];
        values.reverse();
        alert(values);//5,4,3,2,1

        let vaules2 = [0, 1, 5, 10, 15];
        alert(vaules2.sort());//0,1,10,15,5

        /**
         *sort 接受一个比较函数 升序排列
         */
        function compare(value1, value2) {
            if (value1 < value2) {
                return -1;
            }else if (value1 > value2) {
                return 1;
            } else {
                return 0;
            }
        }
        alert(vaules2.sort(compare));//0,1,5,10,15
        /**
         * 降序排列
         * @param value1
         * @param value2
         * @returns {number}
         */
        function compare2(value1, value2) {
            if (value1 < value2) {
                return 1;
            }else if (value1 > value2) {
                return -1;
            } else {
                return 0;
            }
        }
        alert(vaules2.sort(compare2));//15,10,5,1,0



    </script>
</head>
<body>
重排序
</body>
</html>